package com.csw.shuanfa.SuanFa;

/*两个list集合
                ["111”,"222”,"333”,"444”,"555”,"666”,"777”]
            ["aaa”,"bbb”]
        我想把第二个集合的元素随机插入到第一个集合中,还要保证第二个集合元素都排在前六位*/
public class TwoShuZuChaRu {
    public static void main(String[] args) {
        String[] a1 = {"111", "222", "333", "444", "555", "666", "777"};
        suzuDY(a1);
        String[] b1 = {"aaa", "bbb"};
        suzuDY(b1);
        //第一次插入，位置0-4；
        String[] a2 = new String[a1.length + 1];
        chuLi(a1, b1, a2, 0);
        //第二次插入，位置0-5；
        String[] a3 = new String[a2.length + 1];
        chuLi(a2, b1, a3, 1);
        suzuDY(a3);
    }

    private static void suzuDY(String[] a1) {
        for (int i = 0; i < a1.length; i++) {
            if (i != a1.length - 1) {
                System.out.print(a1[i] + ",");
            } else {
                //a1[i]);
            }
        }
    }

    private static void chuLi(String[] a1, String[] b1, String[] a2, int i2) {
        int index1 = (int) (Math.random() * (Math.min(a1.length, 4 + i2)));
        //index1]" + index1);
        boolean a1CR = false;
        for (int i = 0; i < a2.length; i++) {
            if (index1 == i) {
                a2[i] = b1[i2];
                a1CR = true;
            } else {
                if (a1CR) {
                    a2[i] = a1[i - 1];
                } else {
                    a2[i] = a1[i];
                }
            }
        }
    }
}